﻿using Microsoft.AspNetCore.Mvc;
using Queer.Entity;
using Queer.IBusiness.OrganizationManage;
using Queer.Model.Param.OrganizationManage;
using Queer.Util.Model;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Queer.WebApi.Areas.Admin.OrganizationManage
{
    /// <summary>
    /// 创 建：
    /// 日 期：2021-04-07 16:44
    /// 描 述：机构管理控制器类
    /// </summary>

    [Route("OrganizationManage/[controller]")]
    public class OrganizationsController : BaseAdminController
    {
        private readonly IOrganizationsBLL _organizationsBLL;

        public OrganizationsController(IOrganizationsBLL organizationsBLL)
        {
            _organizationsBLL = organizationsBLL;
        }

        #region 获取数据

        /// <summary>
        /// 条件查询
        /// </summary>
        [HttpGet]
        public async Task<TData<List<OrganizationsEntity>>> GetListJson([FromQuery] OrganizationsListParam param)
        {
            TData<List<OrganizationsEntity>> obj = await _organizationsBLL.GetList(param);
            return obj;
        }

        /// <summary>
        /// 条件查询-分页
        /// </summary>
        [HttpGet]
        public async Task<TData<List<OrganizationsEntity>>> GetPageListJson([FromQuery] OrganizationsListParam param, [FromQuery] Pagination pagination)
        {
            TData<List<OrganizationsEntity>> obj = await _organizationsBLL.GetPageList(param, pagination);
            return obj;
        }

        /// <summary>
        /// 根据ID查询
        /// </summary>
        [HttpGet]
        public async Task<TData<OrganizationsEntity>> GetFormJson([FromQuery] long id)
        {
            TData<OrganizationsEntity> obj = await _organizationsBLL.GetEntity(id);
            return obj;
        }

        #endregion

        #region 提交数据

        /// <summary>
        /// 新增/修改 数据
        /// </summary>
        [HttpPost]
        public async Task<TData<string>> SaveFormJson([FromBody] OrganizationsEntity entity)
        {
            TData<string> obj = await _organizationsBLL.SaveForm(entity);
            return obj;
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        [HttpPost]
        public async Task<TData> DeleteFormJson([FromBody] ParamModel model)
        {
            TData obj = await _organizationsBLL.DeleteForm(model.ids);
            return obj;
        }

        #endregion
    }
}